import { defHttp, getServerType } from '@/lib/js/http'
import { RequestMethodEnum, ServerTypeEnum } from '@/lib/js/http/enums'


function getLogintUrl(){
  const serverType = getServerType()
  let url = ''

  switch(serverType){
    case ServerTypeEnum.new:
      url = '/api/login'
      break
    case ServerTypeEnum.old:
      url = '/api/v9/hey-noble/login/sms-verify'
      break
    case ServerTypeEnum.zhangkai:
      url = 'api/v9/bobvote/verify'
      break
  }
  return url
}

function getSmsCodeUrl(){
  const serverType = getServerType()
  let url = ''

  switch(serverType){
    case ServerTypeEnum.new:
      url = '/api/verify'
      break
    case ServerTypeEnum.old:
      url = '/api/v9/hey-noble/login/sms-code'
      break
    case ServerTypeEnum.zhangkai:
      url = 'api/v9/bobvote/send-code'
      break
  }
  return url
}

/*
* 发送验证码
* */
export function smsCode(phone: number) {
  const url = getSmsCodeUrl()
  return defHttp.request<any>({
    url,
    method: RequestMethodEnum.POST,
    data: { phone }
  }, {
    isNeedToken: false
  })
}

/*
* 登录
* */
export function goLogin(phone: number, code: number) {
  const url = getLogintUrl()
  return defHttp.request<any>({
    url,
    method: RequestMethodEnum.POST,
    data: { phone, code }
  }, {
    isNeedToken: false
  })
}
